import request from '@/utils/request'

export function fetchList(url, query) {
  return request({
    url: url,
    method: 'get',
    params: query
  })
}

export function fetchTableInfo(url) {
  return request({
    url: url,
    method: 'get',
    params: {}
  })
}

export function fetchInputs(url) {
  return request({
    url: url,
    method: 'get'
  })
}

export function fetchInfo(url, id) {
  return request({
    url: url,
    method: 'get',
    params: { id }
  })
}

export function editInfo(url, id, data) {
  if (id) {
    if (url.indexOf('?') > 0) {
      url = url + '&id=' + id
    } else {
      url = url + '?id=' + id
    }
  }

  return request({
    url: url,
    method: 'post',
    data
  })
}

export function batchDelete(url, ids) {
  return request({
    url: url,
    method: 'delete',
    query: {
      ids
    }
  })
}

export function deleteInfo(url, id) {
  return request({
    url: url,
    method: 'delete',
    data: {
      id,
      ids: [id]
    }
  })
}

export function createInfo(url, data) {
  return request({
    url: url,
    method: 'post',
    data
  })
}

export function batchAjax(url, data, method) {
  if (method === 'post') {
    return request({
      url: url,
      method: method,
      data
    })
  } else {
    return request({
      url: url,
      method: method,
      params: data
    })
  }
}
